package com.akk.utils;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
public class AppendFile {
    
    /**   
     * 追加文件：使用FileWriter   
     *    
     * @param fileName   
     * @param content   
     */    
    public static void appendToFile(String fileName, String content) {
        File file = new File(fileName);
        if(!file.exists()){
            try {
                file.createNewFile();
                System.out.println("创建文件");
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        FileWriter writer = null;  
        try {     
            // 打开一个写文件器，构造函数中的第二个参数true表示以追加形式写文件     
            writer = new FileWriter(fileName, true);     
            writer.write(content);       
        } catch (IOException e) {     
            e.printStackTrace();     
        } finally {     
            try {     
                if(writer != null){  
                    writer.close();     
                }  
            } catch (IOException e) {     
                e.printStackTrace();     
            }     
        }   
    }     

  
    public static void main(String[] args) {  
        for (int i = 10;i>0;i--){
            appendToFile("d://text.txt","aaa");
            appendToFile("d://text.txt",System.getProperty("line.separator"));
        }
    }  
}